package com.huihui.fragment;


import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

/**
 * Created by Administrator on 2018/8/13.
 */

public class BaseFragment extends Fragment {
    protected final String TAG = getClass().getSimpleName();

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    // 显示输入法
    protected void showInput(Context context, final View focusView) {
        focusView.requestFocus();
        final InputMethodManager imm = (InputMethodManager) context
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        focusView.post(new Runnable() {
            @Override
            public void run() {

                imm.showSoftInput(focusView, InputMethodManager.RESULT_UNCHANGED_SHOWN);
            }
        });
    }
    protected void showkeyboard(View view) {
        InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
    }

    // 隐藏输入法
    protected void hideInput(Context context) {
        final View view = ((Activity) context).getWindow().peekDecorView();
        if (view != null && view.getWindowToken() != null) {
            final InputMethodManager imm = (InputMethodManager) context
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            view.post(new Runnable() {
                @Override
                public void run() {

                    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                }
            });
        }
    }
}
